/*******************************************************************************
 * Copyright 2011, 2012 Chris Banes.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package com.taropan.wallpaper.model;

import java.util.ArrayList;
import java.util.List;

import com.taropan.wallpaper.R;
import com.taropan.wallpaper.widget.NetworkedCacheableImageView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CategoryListAdapter extends BaseAdapter {

	private final Context mContext;
	private List<CategoryEntry> categorylist = null;
	
	public CategoryListAdapter(Context context,List<CategoryEntry> pugUrls) {
		categorylist = pugUrls;
		mContext = context;
	}

	@Override
	public int getCount() {
		return null != categorylist ? categorylist.size() : 0;
	}

	@Override
	public CategoryEntry getItem(int position) {
		return categorylist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (null == convertView) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.gridview_item_layout, parent, false);
		}

		NetworkedCacheableImageView imageView = (NetworkedCacheableImageView) convertView.findViewById(R.id.nciv_pug);
		TextView status = (TextView) convertView.findViewById(R.id.tv_status);
		imageView.loadImage(categorylist.get(position).getUrl(), false);

		status.setText(categorylist.get(position).getName());
		status.setBackgroundColor(mContext.getResources().getColor(R.color.translucent_green));

		return convertView;
	}

}
